package com.itcat.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itcat.api.mysql.CmsSubjectProductRelationApi;
import com.itcat.mapper.CmsSubjectProductRelationMapper;
import com.itcat.mysql.pojo.CmsSubjectProductRelation;
import com.itcat.mysql.pojo.PmsProductLadder;
import com.itcat.mysql.pojo.PmsSkuStock;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-04 0:40
 */
@DubboService
public class CmsSubjectProductRelationApiImpl implements CmsSubjectProductRelationApi {

    @Autowired
    private CmsSubjectProductRelationMapper cmsSubjectProductRelationMapper;

    /**
     * 保存专题和商品关系
     * @param subjectProductRelationList
     */
    @Override
    public void saveList(List<CmsSubjectProductRelation> subjectProductRelationList) {
        cmsSubjectProductRelationMapper.batchInsert(subjectProductRelationList);
    }

    /**
     * 获取专题和商品关系
     * @param productId
     * @return
     */
    @Override
    public List<CmsSubjectProductRelation> findByProductId(Long productId) {
        LambdaQueryWrapper<CmsSubjectProductRelation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CmsSubjectProductRelation::getProductId, productId);
        List<CmsSubjectProductRelation> cmsSubjectProductRelationList = cmsSubjectProductRelationMapper.selectList(queryWrapper);
        return cmsSubjectProductRelationList;
    }

    /**
     * 更新专题和商品关系
     * @param subjectProductRelationList
     */
    @Override
    public void updateList(List<CmsSubjectProductRelation> subjectProductRelationList) {
        cmsSubjectProductRelationMapper.batchUpdate(subjectProductRelationList);
    }

    /**
     * 删除响应商品id的数据
     * @param productId
     */
    @Override
    public void deleteByProductId(Long productId) {
        LambdaQueryWrapper<CmsSubjectProductRelation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(productId != null, CmsSubjectProductRelation::getProductId, productId);
        cmsSubjectProductRelationMapper.delete(queryWrapper);
    }
}
